<?php
/**************************************************************************
 *
 *   Copyright 2010 American Public Media Group
 *
 *   This file is part of AIR2.
 *
 *   AIR2 is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   AIR2 is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with AIR2.  If not, see <http://www.gnu.org/licenses/>.
 *
 *************************************************************************/


/*
|---------------------------------------------------------------
| DEFINE APPLICATION CONSTANTS
|---------------------------------------------------------------
|
| EXT		- The file extension.  Typically ".php"
| SELF		- The name of THIS file (typically "index.php")
| FCPATH	- The full server path to THIS file
| BASEPATH	- The full server path to the "system" folder
| DOCPATH   - The full doctrine "lib" folder path
| APPPATH	- The full server path to the "application" folder
|
*/
define('EXT', '.php');
define('SELF', 'init.php');
define('FCPATH', str_replace(SELF, '', __FILE__));
define('BASEPATH', realpath(FCPATH.'../lib/codeigniter/system').'/');
define('DOCPATH', realpath(FCPATH.'../lib/doctrine/lib').'/');
define('APPPATH', realpath(FCPATH).'/');
define('AIR2_DOCROOT', realpath(FCPATH).'/../public_html/');
define('AIR2_ENVIRONMENT', 'dev'); // possible values are 'prod' and 'dev'
$my_profile = APPPATH.'../etc/my_profile';
if (file_exists($my_profile)) {
    define('AIR2_PROFILE', trim(file_get_contents($my_profile)));
}
else {
    define('AIR2_PROFILE', AIR2_ENVIRONMENT);
}

$search_ini = parse_ini_file(realpath(APPPATH.'../etc/search.ini'), true);
if (!count($search_ini)) {
    die("etc/search.ini failed to load");
}
define('AIR2_SEARCH_URL',       $search_ini[AIR2_PROFILE]['uri']);
define('AIR2_SEARCH_DOCROOT',   $search_ini[AIR2_PROFILE]['root']);

$db_ini = parse_ini_file(realpath(APPPATH.'../etc/db_registry.ini'), true);
if (!count($db_ini)) {
    die("etc/db_registry.ini failed to load");
}
if (isset($db_ini[AIR2_PROFILE]['base_url'])) {
    define('AIR2_BASE_URL', $db_ini[AIR2_PROFILE]['base_url']);
}

define('AIR2_CSV_PATH',         '/tmp/air2/csv');

/* set up include path */
$air2_include_paths = array(
    APPPATH.'libraries',
    APPPATH.'models',
    APPPATH.'../lib',
    APPPATH.'../lib/shared',
    APPPATH.'../lib/shared/passwordreset',
    APPPATH.'../lib/mover',
);
set_include_path(implode(':', $air2_include_paths));

require_once APPPATH.'config/air2_constants.php';
require_once 'Carper.php';
require_once 'AIR2_Exception.php';
require_once 'AIR2_Utils.php';
